package com.googlecode.stateless4j.transitions;

/**
 * Defines the transition from one state to another.
 *
 * @param <TState>
 * @param <TTrigger>
 */
public class Transition<TState, TTrigger>
{
    private final TState source;
    private final TState destination;
    private final TTrigger trigger;

    /// <summary>
    /// Construct a transition.
    /// </summary>
    /// <param name="source">The state transitioned from.</param>
    /// <param name="destination">The state transitioned to.</param>
    /// <param name="trigger">The trigger that caused the transition.</param>
    public Transition(TState source, TState destination, TTrigger trigger)
    {
        this.source = source;
        this.destination = destination;
        this.trigger = trigger;
    }

    /// <summary>
    /// The state transitioned from.
    /// </summary>
    public TState getSource()
    {
        return source;
    }

    /// <summary>
    /// The state transitioned to.
    /// </summary>
    public TState getDestination()
    {
        return destination;
    }

    /// <summary>
    /// The trigger that caused the transition.
    /// </summary>
    public TTrigger getTrigger()
    {
        return trigger;
    }

    /// <summary>
    /// True if the transition is a re-entry, i.e. the identity transition.
    /// </summary>
    public Boolean isReentry()
    {
        return getSource().equals(getDestination());
    }
}